
# MqRPC整个包中的异常


class MqRPCException(Exception):
    # 异常父类
    def __init__(self, exception_name, status, msg, func_name):
        self.status = status
        self.msg = msg
        self.func_name = func_name
        self.exception_name = exception_name

    def __str__(self):
        return "status:%s, %s: %s in %s" % (self.status, self.exception_name, self.msg, self.func_name)

    @staticmethod
    def get_exception(exception_name, status, func_name, msg=None):
        if status == "200":
            return None
        elif status == "100":
            return MqRPCTimeOutException(func_name)
        elif status == "404":
            return MqRPCNotFoundProcess(func_name)
        elif status == "500":
            return MqRPCRequestError(func_name)
        elif status == "600":
            return MqRPCParametersError(exception_name, msg, func_name)
        else:
            return MqRPCOtherError(exception_name, msg, func_name)


class MqRPCTimeOutException(MqRPCException):

    def __init__(self, func_name):
        super().__init__(MqRPCTimeOutException.__name__, "100", "RPC请求超时", func_name)


class MqRPCNotFoundProcess(MqRPCException):

    def __init__(self, func_name):
        super().__init__(MqRPCNotFoundProcess.__name__, "404", "没有在远程端找到该过程", func_name)


class MqRPCRequestError(MqRPCException):

    def __init__(self, func_name):
        super().__init__(MqRPCRequestError.__name__, "500", "request消息格式错误", func_name)


class MqRPCParametersError(MqRPCException):

    def __init__(self, exception_name,  msg, func_name):
        super().__init__(exception_name, "600", "参数不正确: " + msg, func_name)


class MqRPCOtherError(MqRPCException):

    def __init__(self, exception_name, msg, func_name):
        super().__init__(exception_name, "700", msg, func_name)
